﻿/*******************************
 * 
 * 数据访问层
 * 询价数据
 * 
 * 问价添加、询价显示、
 * Author：JXL
 * 
 * 
 ***************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using Model;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DAL
{
    public class InquiryDAL : IInquiryDAL
    {

        public static string Conns = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;


        /// <summary>
        /// 问价添加
        /// </summary>
        /// <param name="mo"></param>
        /// <returns></returns>
        public int InquiryAdd(Inquiry mo)
        {
            using (SqlConnection conn = new SqlConnection(Conns))
            {
                conn.Open();
                string sql = string.Format("insert into Inquiry(ProjectNumber,Inquiry_UnitPrice,Inquiry_Content,Inquiry_Time) values('{0}','{1}','{2}',GETDATE())", mo.projectNumber, mo.inquiry_UnitPrice, mo.inquiry_Content) + "; update basic_Info set basic_UnitPrice='" + mo.inquiry_UnitPrice + "' where ProjectNumber='" + mo.projectNumber + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                int i = cmd.ExecuteNonQuery();
                conn.Close();
                return i;
            }
        }


        /// <summary>
        /// 询价显示
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<Inquiry> InquiryShow(string name)
        {
            using (SqlConnection conn = new SqlConnection(Conns))
            {
                conn.Open();
                string sql = string.Format("select * from Inquiry where ProjectNumber='{0}'",name);
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader read = cmd.ExecuteReader();
                List<Inquiry> list = new List<Inquiry>();
                while (read.Read())
                {
                    Inquiry mo = new Inquiry();
                    mo.inquiry_Id = Convert.ToInt32(read["inquiry_Id"]);
                    mo.inquiry_UnitPrice = read["inquiry_UnitPrice"].ToString();
                    mo.inquiry_Content = read["inquiry_Content"].ToString();
                    mo.inquiry_Times = read["inquiry_Time"].ToString();
                    list.Add(mo);
                
                }
                conn.Close();
                return list;
            }
        }
    }
}
